package nc.tb.cube.model;

import nc.tb.dim.DimDef;
import nc.tb.dim.data.DimManager;
import nc.tb.pub.IDimType;
import nc.tb.pub.ref.FreeTypeRefPane;
import nc.tb.pub.util.NtbLogger;
import nc.ui.pub.bill.BillCellEditor;

public class VersionCellEditor extends BillCellEditor {

    public VersionCellEditor(final FreeTypeRefPane tbref) {
    	super(tbref);
        delegate = new EditorDelegate() {
            public void setValue(Object value) {
                tbref.setValue((value != null) ? value.toString() : "");
            }
            public Object getCellEditorValue() {
                if (tbref.getSelectedBusiObj() == null)
                    return tbref.getText();
                else
                    return tbref.getSelectedBusiObj();
            }
        };
    }
    public java.awt.Component getTableCellEditorComponent (
        	javax.swing.JTable table, 
        	Object value, 
        	boolean isSelected, 
        	int row, 
        	int column)
    {
    	try { 
    		DimDef dd = DimManager.getDimDef(IDimType.VERSION);
	        ((FreeTypeRefPane) editorComponent).setRootObject(dd);
	        ((FreeTypeRefPane) editorComponent).setLeafObjects(DimManager.getDimMembers(dd));
    	} catch (Exception e) {
    		NtbLogger.error(e);
		}
        delegate.setValue(value);
        return editorComponent;
    }
    
}
